// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: false },
  sourcemap: false,
  typescript: { strict: false, shim: false },
  // spaLoadingTemplate: 'spa-loading-template.html',
  srcDir: 'src',
  modules: [
    'dayjs-nuxt',
    '@pinia/nuxt',
    '@pinia-plugin-persistedstate/nuxt',
    '@vueuse/nuxt',
    '@element-plus/nuxt',
    '@nuxtjs/i18n',
    '@nuxt/image',
  ],

  i18n: {
    strategy: 'no_prefix', // 添加路由前缀的方式
    locales: ['en', 'zh'], // 配置语种
    defaultLocale: 'zh', // 默认语种
    vueI18n: '~/i18n/config.js', // 通过vueI18n配置
  },

  css: ['~/assets/style/scss/main.scss', 'animate.css/animate.min.css'],

  // 此处配置的目录中的任何组件都可以在整个页面、布局（和其他组件）中使用，而无需显式导入它们。
  imports: { dirs: ['types', 'stores', 'api'] },

  build: { transpile: [/echarts/] },

  dayjs: {
    plugins: ['duration', 'relativeTime'],
    locales: ['en', 'zh-cn'],
    defaultLocale: ['zh-cn', {
      relativeTime: {
        future: '刚刚',
        past: '%s前',
        s: '几秒',
        m: '1 分钟',
        mm: '%d 分钟',
        h: '1 小时',
        hh: '%d 小时',
        d: '1 天',
        dd: '%d 天',
        M: '1 个月',
        MM: '%d 个月',
        y: '1 年',
        yy: '%d 年',
      },
    }],
  },

  app: {
    head: {
      title: process.env.NUXT_PUBLIC_TITLE,
      meta: [
        { charset: 'utf-8' },
        { name: 'viewport', content: '' },
        { name: 'keywords', content: '' },
        { name: 'description', content: '' },
        { name: 'format-detection', content: 'telephone=no' },
        // pc 等比例缩放
        // { name: 'viewport', content: 'user-scalable=yes' }
      ],
      link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
      style: [],
      script: [
        // { src: '//cdn.jsdelivr.net/npm/eruda', type: 'text/javascript' },
        // { children: 'eruda.init();', type: 'text/javascript' }
      ],
      noscript: [{ children: 'JavaScript is required' }],
    },
  },

  vite: {
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@use "~/assets/style/scss/theme.scss" as *;',
        },
      },
    },
    build: {
      chunkSizeWarningLimit: 2000,
      commonjsOptions: { transformMixedEsModules: true },
    },

    esbuild: {
      drop: import.meta.env.NUXT_PUBLIC_DELETE_CONSOLE ? ['console', 'debugger'] : [],
    },
  },

  piniaPersistedstate: {
    cookieOptions: {
      domain: import.meta.env.NUXT_PUBLIC_COOKIE_DOMAIN,
      path: import.meta.env.NUXT_PUBLIC_COOKIE_PATH,
      sameSite: import.meta.env.NUXT_PUBLIC_COOKIE_SAMESITE,
    },
    debug: import.meta.env.NUXT_PUBLIC_COOKIE_DEBUG,
  },

  runtimeConfig: {
    public: {
      title: import.meta.env.NUXT_PUBLIC_TITLE,
      api: {
        baseUrl: import.meta.env.NUXT_PUBLIC_API_BASEURL,
      },
    },
  },

  devServer: {
    // https: {
    //   key: fs.readFileSync(path.resolve(__dirname, 'server.key'), 'utf-8'),
    //   cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'), 'utf-8')
    // }
    port: 8099,
    host: '192.168.2.196',
  },

  nitro: {
    compressPublicAssets: true,
    esbuild: {
      options: {
        target: 'esnext',
      },
    },
    // devProxy: {
    //   host: '127.0.0.1',
    // },
  },

  compatibilityDate: '2024-08-13',
})
